package com.anyou.mall.pla.service.impl;

import java.util.List;
import com.anyou.common.utils.DateUtils;
import com.anyou.mall.sho.vo.PostionVo;
import com.anyou.mall.util.QQmapUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anyou.mall.pla.mapper.PlaCarPartsCityMapper;
import com.anyou.mall.pla.domain.PlaCarPartsCity;
import com.anyou.mall.pla.service.IPlaCarPartsCityService;

/**
 * 汽配城Service业务层处理
 *
 * @author YLJ
 * @date 2022-03-18
 */
@Service
public class PlaCarPartsCityServiceImpl extends ServiceImpl<PlaCarPartsCityMapper, PlaCarPartsCity> implements IPlaCarPartsCityService
{
    @Autowired
    private PlaCarPartsCityMapper plaCarPartsCityMapper;

    /**
     * 查询汽配城
     *
     * @param carPartsCityId 汽配城主键
     * @return 汽配城
     */
    @Override
    public PlaCarPartsCity selectPlaCarPartsCityByCarPartsCityId(Long carPartsCityId)
    {
        return plaCarPartsCityMapper.selectPlaCarPartsCityByCarPartsCityId(carPartsCityId);
    }

    /**
     * 查询汽配城列表
     *
     * @param plaCarPartsCity 汽配城
     * @return 汽配城
     */
    @Override
    public List<PlaCarPartsCity> selectPlaCarPartsCityList(PlaCarPartsCity plaCarPartsCity)
    {
        return plaCarPartsCityMapper.selectPlaCarPartsCityList(plaCarPartsCity);
    }

    /**
     * 新增汽配城
     *
     * @param plaCarPartsCity 汽配城
     * @return 结果
     */
    @Override
    public int insertPlaCarPartsCity(PlaCarPartsCity plaCarPartsCity)
    {
        plaCarPartsCity.setCreateTime(DateUtils.getNowDate());
        plaCarPartsCity.setDelFlag("0");
        //拼接完整的地址
        String addr=plaCarPartsCity.getProvince()+plaCarPartsCity.getCity()+plaCarPartsCity.getArea()+plaCarPartsCity.getDetailed();
        //腾讯地图根据地址计算经纬度
        PostionVo position = QQmapUtil.getPosition(addr);
        plaCarPartsCity.setCarPartsCityLatitude(position.getX()); //纬度
        plaCarPartsCity.setCarPartsCityLongitude(position.getY()); //经度

//        return plaCarPartsCityMapper.insertPlaCarPartsCity(plaCarPartsCity);
        return plaCarPartsCityMapper.insert(plaCarPartsCity);
    }

    /**
     * 修改汽配城
     *
     * @param plaCarPartsCity 汽配城
     * @return 结果
     */
    @Override
    public int updatePlaCarPartsCity(PlaCarPartsCity plaCarPartsCity)
    {
        plaCarPartsCity.setUpdateTime(DateUtils.getNowDate());
        //拼接完整的地址
        String addr=plaCarPartsCity.getProvince()+plaCarPartsCity.getCity()+plaCarPartsCity.getArea()+plaCarPartsCity.getDetailed();
        //腾讯地图根据地址计算经纬度
        PostionVo position = QQmapUtil.getPosition(addr);
        plaCarPartsCity.setCarPartsCityLatitude(position.getX()); //纬度
        plaCarPartsCity.setCarPartsCityLongitude(position.getY()); //经度
//        return plaCarPartsCityMapper.updatePlaCarPartsCity(plaCarPartsCity);
        return plaCarPartsCityMapper.updateById(plaCarPartsCity);
    }

    /**
     * 批量删除汽配城
     *
     * @param carPartsCityIds 需要删除的汽配城主键
     * @return 结果
     */
    @Override
    public int deletePlaCarPartsCityByCarPartsCityIds(Long[] carPartsCityIds)
    {
        return plaCarPartsCityMapper.deletePlaCarPartsCityByCarPartsCityIds(carPartsCityIds);
    }

    /**
     * 删除汽配城信息
     *
     * @param carPartsCityId 汽配城主键
     * @return 结果
     */
    @Override
    public int deletePlaCarPartsCityByCarPartsCityId(Long carPartsCityId)
    {
        return plaCarPartsCityMapper.deletePlaCarPartsCityByCarPartsCityId(carPartsCityId);
    }
}
